<template>
  <el-card class="box-card" style="width: 1180px">   
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="query">
        <el-form-item>
          <el-button type="success"
            >还款详情</el-button
          >     
        </el-form-item>
      </el-form>
    </div>      
    <el-table :data="repList" border style="width: 100%">
        <el-table-column prop="reId" label="编号">
</el-table-column>
        <el-table-column prop="heTongId" label="合同号" >
</el-table-column>
      <el-table-column prop="name" label="姓名" >
      </el-table-column>
      <el-table-column prop="sumExpirse" label="总期数" width="160">
      </el-table-column>
      <el-table-column prop="nowExpirse" label="当前期数" width="160">
      </el-table-column>
      <el-table-column prop="prepaymentPeriods" label="还款期数"></el-table-column>
      <el-table-column prop="currentSum" label="还款金额">
      </el-table-column> 
      <el-table-column label="操作" width="220">
        <template slot-scope="scope">
          <el-button size="mini" @click="edit(scope.row.reId)"
            >还款</el-button
          >

        </template>
      </el-table-column>      
    </el-table>
    <el-dialog title="还款详情" :visible.sync="dialog.updateshow" width="30%">
      <el-form ref="updateForm" :model="updateForm" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="编号" prop="reId" hidden>
              <el-input v-model="updateForm.reId"  ></el-input>
            </el-form-item>
            <el-form-item label="合同号" prop="heTongId">
              <el-input v-model="updateForm.heTongId"  ></el-input>
            </el-form-item>
            <el-form-item label="总期数" prop="sumExpirse">
              <el-input v-model="updateForm.sumExpirse"></el-input>
            </el-form-item>
            <el-form-item label="当前期数" prop="nowExpirse">
              <el-input v-model="updateForm.nowExpirse"></el-input>
            </el-form-item>
            <el-form-item label="还款期数">
                <el-select v-model="updateForm.prepaymentPeriods" placeholder="请选择还款期数" @change="ch(updateForm.prepaymentPeriods)">
                    <el-option v-for="item in intList"
                  :key="item"
                  :label="item"
                  :value="item"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="还款金额" prop="currentSum">
              <el-input v-model="updateForm.currentSum"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog.updateshow = false">取 消</el-button>
        <el-button type="primary" @click="update()">确 定</el-button>
      </span>
    </el-dialog>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
        intList:{},
        dialog:{
        updateshow:false
      },
      num2:1,
        repList:[],
      query:{
      },
      user:{},
      updateForm:{},
    };
  },
  methods: {
    ch(num){
        this.updateForm.currentSum=this.updateForm.currentSum/this.num2;
        this.updateForm.currentSum=this.updateForm.currentSum*num;
        this.num2=num;
    },
    update(){
        this.updateForm.by1="未通过";
        this.$axios.put("/repays",this.updateForm)
        .then(res=>{
            if(res.data.code==200){
                this.$message.success("还款成功");
                this.dialog.updateshow=false;
                this.loadRes();
            }else{
                this.$message.error("账户余额不足");
            }
        })
    },
    edit(id){
        this.$axios.get("/repays/sell/"+id)
        .then(res=>{
            this.updateForm=res.data.data.repay;
            this.intList=res.data.data.dang;
        })
        this.dialog.updateshow=true;
    },
    loadRes(){
        this.user=JSON.parse(sessionStorage.getItem("user")); 
        this.$axios.post("/repays/user",this.user)
        .then(res=>{
                this.repList=res.data.data.list;
        })
    },
  },
  mounted(){
    this.loadRes();
   
  }
};
</script>